package org.nobject.common.fan.datagen.name;

import org.nobject.common.fan.datagen.DistrictGen;
import org.nobject.common.fan.datagen.RandomGen;
import org.nobject.common.fan.datagen.StringGen;

/**
 * 公司名称生成
 *
 * @author benson
 * @version 1.0
 */
public class CompanyNameGen implements RandomGen{
	public static String[] zhchars=new String[]{};
	/**
	 * 序号_商业领域_地产
	 */
	public static int IDX_BUSSINESSRANGE_ESTATE=0;
	
	/**
	 * 序号_商业领域_IT
	 */
	public static int IDX_BUSSINESSRANGE_IT=1;
	
	/**
	 * 序号_商业领域_广告
	 */
	public static int IDX_BUSSINESSRANGE_ADVERTISE=2;
	
	/**
	 * 序号_商业领域_教育
	 */
	public static int IDX_BUSSINESSRANGE_EDU=3;
	
	/**
	 * 序号_商业领域_金融
	 */
	public static int IDX_BUSSINESSRANGE_FINANCIAL=4;
	
	/**
	 * 商业领域_L1
	 */
	public static String [] bussinessRangsL1={"地产","IT","广告","教育","金融","能源","其它"};
	
	/**
	 * 商业领域_L2
	 */
	public static String [][] bussinessRangsL2={
		{"房地产","建筑"}
		,{"软件开发","硬件集成","网络工程","设计","科技"}
		,{"广告","文化传播"}
		,{"教育培训","咨询"}
		,{"证券","期货"}
		,{"化工","石油","石化","能源"}
		,{"服饰","食品","进出口","机械"}
	};
	
	/**
	 * 公司类型
	 */
	public static String [] companyTypes={"股份有限","责任有限","有限","中外合资"};
	
	/**
	 * 公司
	 */
	public static String [] companyEnd={"公司","株式会社","集团","厂","办事处"};
	
	/**
	 * genCompanyName
	 * 
	 * EXP:
	 * 	genCompanyName(null, -1, null)
	 * 
	 * @param districtCode 地区编码
	 * @param bussinessRang
	 */
	public static String genCompanyName(String districtCode,int bussinessRangL1Idx,String companyType){
		
		StringBuffer companyName=new StringBuffer();
		
		String companyDistrictName="";
		
		if(districtCode==null){
			districtCode=DistrictGen.genCityCode();
		}
		if(DistrictGen.isDirectlyCity(districtCode)){
			districtCode=DistrictGen.genProvinceCode();
			companyDistrictName=DistrictGen.getProvinceName(districtCode);
		}else{
			if(random.nextBoolean()){
				districtCode=DistrictGen.genProvinceCode();
				while(districtCode==null){
					districtCode=DistrictGen.genProvinceCode();
				}
				companyDistrictName=DistrictGen.getProvinceName(districtCode);
			}else{
				districtCode=DistrictGen.genCityCode();
				String cityName=DistrictGen.getCityName(districtCode);
				districtCode=DistrictGen.genProvinceCode();while(districtCode==null) districtCode=DistrictGen.genProvinceCode();
				companyDistrictName+=DistrictGen.getProvinceName(DistrictGen.getProvinceCodeByCityCode(districtCode));
				companyDistrictName+=cityName;
			}
		}
		
		//char lastChar=companyDistrictName.charAt(companyDistrictName.length()-1);
//		int cdl=companyDistrictName.length();
//		int c=-1;
//		if((c=companyDistrictName.lastIndexOf("省"))==(cdl-1)||(c=companyDistrictName.lastIndexOf("市"))==cdl||(c=companyDistrictName.lastIndexOf("自治区"))==cdl){
//			
//			companyDistrictName=companyDistrictName.substring(0, companyDistrictName.length()-(c+1));
//		}
		
		
		if(bussinessRangL1Idx==-1){
			bussinessRangL1Idx=random.nextInt(bussinessRangsL1.length);
		}
		
		String [] subBussinessRang=bussinessRangsL2[bussinessRangL1Idx];
		System.err.println(companyName.toString());
		return companyName
			.append(companyDistrictName)
			.append(StringGen.genString(2+random.nextInt(3),3))
			.append(subBussinessRang[random.nextInt(subBussinessRang.length)])
			.append(companyEnd[random.nextInt(companyEnd.length)])
			.toString();
	}
}
